package com.ryan.quartz.scheduler;

import com.ryan.quartz.job.HelloQuartzJob;
import org.quartz.*;

/**
 * @author Rayn on 2017/10/2.
 * @email liuwei412552703@163.com.
 */
public class QuartzStdScheduler {

    public static void main(String[] args) throws SchedulerException {

        SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();

        Scheduler sched = schedFact.getScheduler();

        sched.start();

        // define the job and tie it to our HelloJob class
        JobDetail job = JobBuilder.newJob(HelloQuartzJob.class)
                .withIdentity("myJob", "group1")
                .build();

        // Trigger the job to run now, and then every 40 seconds
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("myTrigger", "group1")
                .startNow()
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInSeconds(40)
                        .repeatForever())
                .build();


        // Tell quartz to schedule the job using our trigger
        sched.scheduleJob(job, trigger);


    }
}
